package com.whut.www.file_storage;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v4.content.AsyncTaskLoader;
import android.util.Log;
/**
 * Created by clvc on 2017/7/7.
 * 真正的速度是看不见的 !
 * Today is today , we will go !
 */
public class CustomLoader extends AsyncTaskLoader<Cursor> {
    private SQLiteDatabase mSQLiteDatabase;
    public CustomLoader(Context context, SQLiteDatabase sqLiteDatabase) {
        super(context);
        mSQLiteDatabase = sqLiteDatabase;
    }
    @Override
    protected void onStartLoading() {
        Log.i("CustomLoader", "---onStartLoading()--->"+Thread.currentThread().getName());
        super.onStartLoading();
        //必须调用forceLoad()执行强制加载,否则不会执行loadInBackground()
        forceLoad();
    }
    @Override
    public Cursor loadInBackground() {
        Log.i("CustomLoader", "---loadInBackground()--->"+Thread.currentThread().getName());
        Cursor cursor = mSQLiteDatabase.rawQuery("select * from tb_words", null);
        return cursor;
    }
}
